﻿package mortal.game.view.medal
{
    import Message.DB.Tables.*;
    import flash.utils.*;
    import mortal.game.resource.tableConfig.*;

    public class MedalCache extends Object
    {
        private var _medalDic:Dictionary;
        private var _medalCatagoryDic:Dictionary;

        public function MedalCache()
        {
            this._medalDic = new Dictionary();
            this._medalCatagoryDic = new Dictionary();
            return;
        }// end function

        public function addMedal(param1:TMedal) : void
        {
            this.removeMedalByCatagoryAndType(param1.catagory, param1.type);
            this._medalDic[param1.code] = param1;
            if (this._medalCatagoryDic[param1.catagory] == null)
            {
                this._medalCatagoryDic[param1.catagory] = new Array();
            }
            (this._medalCatagoryDic[param1.catagory] as Array).push(param1);
            return;
        }// end function

        private function removeMedalByCatagoryAndType(param1:int, param2:int) : void
        {
            var _loc_3:Array = null;
            var _loc_4:TMedal = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            if (this._medalCatagoryDic && this._medalCatagoryDic.hasOwnProperty(param1))
            {
                _loc_3 = this._medalCatagoryDic[param1];
                _loc_5 = _loc_3.length;
                while (_loc_6 < _loc_5)
                {
                    
                    _loc_4 = _loc_3[_loc_6];
                    if (_loc_4.type == param2)
                    {
                        _loc_3.splice(_loc_6, 1);
                        delete this._medalDic[_loc_4.code];
                        break;
                    }
                    _loc_6++;
                }
            }
            return;
        }// end function

        public function get medalDic() : Dictionary
        {
            return this._medalDic;
        }// end function

        public function get ownMedal() : int
        {
            var _loc_1:int = 0;
            var _loc_2:TMedal = null;
            for each (_loc_2 in this._medalDic)
            {
                
                _loc_1++;
            }
            return _loc_1;
        }// end function

        public function isHasMedalByCode(param1:int) : Boolean
        {
            var _loc_5:Boolean = false;
            var _loc_6:TMedal = null;
            var _loc_2:* = MedalConfig.instance.getTmedalByCode(param1);
            var _loc_3:* = this._medalCatagoryDic[_loc_2.catagory];
            var _loc_4:* = _loc_2.type;
            for each (_loc_6 in _loc_3)
            {
                
                if (_loc_6.type == _loc_4)
                {
                    _loc_5 = true;
                    break;
                }
            }
            return _loc_5;
        }// end function

        public function getOwnMedalByCatagoryAndType(param1:int, param2:int) : TMedal
        {
            var _loc_4:TMedal = null;
            var _loc_5:TMedal = null;
            var _loc_3:* = this._medalCatagoryDic[param1];
            for each (_loc_5 in _loc_3)
            {
                
                if (_loc_5.type == param2)
                {
                    _loc_4 = _loc_5;
                    break;
                }
            }
            return _loc_4;
        }// end function

        public function getCurrentCatagoryMedalNum(param1:int) : int
        {
            var _loc_2:int = 0;
            if (this._medalCatagoryDic[param1])
            {
                _loc_2 = (this._medalCatagoryDic[param1] as Array).length;
            }
            return _loc_2;
        }// end function

        public function get medalCatagoryDic() : Dictionary
        {
            return this._medalCatagoryDic;
        }// end function

    }
}
